package com.mybatiscore.jiaocheng.d02mybatis参数;

import com.mybatiscore.Mapper.StudentMapper;
import com.mybatiscore.POJO.Student;
import com.mybatiscore.Util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class d01单个简单参数 {
    /*
      简单类型：
        byte short int long float double char
        Byte Short Integer Long Float Double Character
        String
        java.util.Date
        java.sql.Date
     */

    //一、Long类型
    @Test
    public void testLong(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<Student> studentMappers = mapper.selectById(1L);
        for (Student s:studentMappers){
            System.out.println(s);
        }
        sqlSession.close();
    }

    //二、String
    @Test
    public void testString(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<Student> studentMappers = mapper.selectByName("李四");
        for (Student s:studentMappers){
            System.out.println(s);
        }
        sqlSession.close();
    }

    //三、Data类型
    @Test
    public void testDate() throws Exception {
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
        Date parse = simpleDateFormat.parse("1980-10-11");
        List<Student> studentMappers = mapper.selectByBirth(parse);
        for (Student s:studentMappers){
            System.out.println(s);
        }
        sqlSession.close();
    }

    //四、char
    @Test
    public void testChar() throws Exception {
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<Student> studentMappers = mapper.selectBySex('男');
        for (Student s:studentMappers){
            System.out.println(s);
        }
        sqlSession.close();
    }




}
